@echo off

echo ==================== Checking 7-Zip ===========================================
7z
IF %ERRORLEVEL% NEQ 0 echo 7-Zip not found && goto ReturnAndExit

cd ..\src\

echo ==================== Checking main module and getting version =================
set MODULE=xeniumtool
if not exist %MODULE%.py echo %MODULE%.py not exist && goto ReturnAndExit
for /f "tokens=*" %%a in ('python -c "import %MODULE%; print %MODULE%.__version__"') do set VERSION=%%a
echo Version: %VERSION%

echo ==================== Compiling ================================================
python setup.py py2exe
cd dist

echo ==================== Copying DLLs =============================================
copy ..\..\tools\components\* .

echo ==================== Compressing ==============================================
set ARCHIVE=..\..\dist\xeniumtool_%VERSION%_win32.zip
del %ARCHIVE%
7z a -mx9 %ARCHIVE% *

echo ==================== Cleaning =================================================
cd ..
rmdir /Q /S build dist
cd ..\tools\


:ReturnAndExit
cd ..\tools\
exit /b 1
